package guowei.gulidiscount.discount.service.impl;

import guowei.common.to.MemberPrice;
import guowei.common.to.SkusToCommon;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import guowei.common.utils.PageUtils;
import guowei.common.utils.Query;

import guowei.gulidiscount.discount.dao.MemberPriceDao;
import guowei.gulidiscount.discount.entity.MemberPriceEntity;
import guowei.gulidiscount.discount.service.MemberPriceService;


@Service("memberPriceService")
public class MemberPriceServiceImpl extends ServiceImpl<MemberPriceDao, MemberPriceEntity> implements MemberPriceService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberPriceEntity> page = this.page(
                new Query<MemberPriceEntity>().getPage(params),
                new QueryWrapper<MemberPriceEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void saveMembers(SkusToCommon skusToCommon) {
        List<MemberPrice> memberPrice = skusToCommon.getMemberPrice();
        List<MemberPriceEntity> collect = memberPrice.stream().map(memberPrice1 -> {
            MemberPriceEntity memberPriceEntity = new MemberPriceEntity();
            memberPriceEntity.setMemberLevelName(memberPrice1.getName());
            memberPriceEntity.setSkuId(skusToCommon.getSkuId());
            memberPriceEntity.setMemberPrice(memberPrice1.getPrice());
            return memberPriceEntity;
        }).collect(Collectors.toList());
        this.saveBatch(collect);
    }

}